package com.ermax.aircond.common.service;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.ermax.aircond.common.dao.UserDetailDao;
import com.ermax.aircond.common.dao.UserGroupDao;
import com.ermax.aircond.common.domain.UserDetail;
import com.ermax.aircond.common.domain.UserGroup;

@Service("userFilterService")
@Scope(value = "singleton")
public class UserFilterService {
	
	private static final Logger logger = LoggerFactory.getLogger(UserFilterService.class);

	@Resource(name = "userDetailDao")
	private UserDetailDao userDetailDao;

	@Resource(name = "userGroupDao")
	private UserGroupDao userGroupDao;
	
	private static List<UserDetail> adminUserDetailList = null;
	
	public List<UserDetail> filterAdminUserDetails(List<UserDetail> sourceList){
		if(adminUserDetailList == null){
			try{
				reset();
			}catch(Exception ex){
				logger.error(ex.getLocalizedMessage());
			}
		}
		sourceList.removeAll(adminUserDetailList);		
		return sourceList;
	}
		
	
	public void reset() throws Exception {
		List<UserGroup> adminUserGroup = userGroupDao.findUserGroupByKeyword("ADMIN");	
		adminUserDetailList  = userDetailDao.findUserDetails(adminUserGroup);
	}
}
